import { Message } from 'element-ui'
export default that => {
    that.graph.on('on-canvas-dragend', e => {
    // console.log('画布被拖拽', e)
        that.canvasOffset.x = e.dx
        that.canvasOffset.y = e.dy
    })

    that.graph.on('on-node-mouseenter', e => {
        if (e && e.item) {
            // const model = e.item.get('model');

            // model.style.fill = 'rgba(24, 144, 255, .3)';
        }
    })

    that.graph.on('on-canvas-click', e => {
        that.tabPosition = 'flow'
    })

    that.graph.on('after-node-selected', e => {
    // console.log('节点被选中', e.item.get('model'))
        that.configVisible = !!e
        if (e && e.item) {
            const model = e.item.get('model')

            that.config = model
            that.label = model.label
            that.labelCfg = {
                fill: model.labelCfg.fill,
                fontSize: model.labelCfg.fontSize
            }
            that.node = {
                fill: model.style.fill,
                borderColor: model.style.stroke,
                lineDash: model.style.lineDash || 'none',
                width: model.style.width,
                height: model.style.height,
                shape: model.type
            }

            // model.label = e.item.get('id');
            /* that.graph.updateItem(e.item, {
        x: 100,
        y: 100,
      }); */
        }
        that.afterNodeSelected(that.config)
    })

    that.graph.on('after-edge-selected', e => {
    // console.log('边选中', e.item.get('model'))
        that.configVisible = !!e
        if (e && e.item) {
            that.config = e.item.get('model')

            // that.graph.updateItem(e.item, {
            //   // shape: 'line-edge',
            //   style: {
            //     radius: 10,
            //     lineWidth: 2
            //   }
            // })
        }
        that.afterEdgeSelected(that.config)
    })

    that.graph.on('on-edge-mousemove', e => {
        if (e && e.item) {
            that.tooltip = e.item.get('model').label
            that.left = e.clientX + 40
            that.top = e.clientY - 20
        }
    })

    that.graph.on('on-node-mousemove', e => {
        if (e && e.item) {
            that.tooltip = e.item.get('model').id
            that.left = e.clientX + 40
            that.top = e.clientY - 20
        }
    })

    that.graph.on('on-node-mouseleave', e => {
        if (e && e.item) {
            that.tooltip = ''
        }
    })

    that.graph.on('on-edge-mouseleave', e => {
        if (e && e.item) {
            that.tooltip = ''
        }
    })

    that.graph.on('before-node-removed', ({ target, callback }) => {
        if (target.getModel().type === 'rect-node-endpoint') {
            Message({
                message: '起始节点不能删除！',
                type: 'warning'
            })
        } else {
            // eslint-disable-next-line standard/no-callback-literal
            callback(true)
        }
    // setTimeout(() => {
    // 确认提示
    // eslint-disable-next-line standard/no-callback-literal
    // callback(true)
    // }, 100)
    })

    that.graph.on('after-node-dblclick', e => {
        if (e && e.item) {
            console.log(e.item)
        }
    })

    that.graph.on('before-edge-add', ({ source, target, sourceAnchor, targetAnchor }) => {
        setTimeout(() => {
            that.addEdge({ source, target, sourceAnchor, targetAnchor })
        }, 100)
    })
}
